package com.wnhz.work.jy.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.view.SignCalendar;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * -----签到
 */
public class SignInActivity extends BaseActivity implements View.OnClickListener {
    private TextView title, right;
    private SignCalendar calendar;
    private String date, date1;
    private int years;
    private String months;
    private Button btn_sign;

    private TextView tv_time, tv_days;

    private int days = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);

        initData();
        initView();
    }

    private void initData() {

    }

    private void initView() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("签到");
        findViewById(R.id.btn_main_right).setVisibility(View.VISIBLE);
        findViewById(R.id.view_main_right_text).setVisibility(View.VISIBLE);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.btn_sign).setOnClickListener(this);
        findViewById(R.id.rl_detail).setOnClickListener(this);
        findViewById(R.id.rl_shopping).setOnClickListener(this);

        right = (TextView) findViewById(R.id.view_main_right_text);
        right.setText("规则");
        right.setTextColor(0xffff3c3d);

        calendar = (SignCalendar) findViewById(R.id.sc_main);
        tv_time = (TextView) findViewById(R.id.tv_time);
        tv_days = (TextView) findViewById(R.id.tv_days);

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
        date = formatter.format(curDate);

        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy年MM月");
        Date curDate1 = new Date(System.currentTimeMillis());// 获取当前时间
        date1 = formatter1.format(curDate1);

        tv_time.setText(date1);
        tv_days.setText("已连续签到" + days + "天");
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;

            //规则
            case R.id.btn_main_right:
                break;

            //签到
            case R.id.btn_sign:
                List<String> list = new ArrayList<String>();
                list.add("2016-06-30");
                list.add(date);
                // calendar.setCalendarDaysBgColor(list,
                // R.drawable.bg_sign_today);
                calendar.addMarks(list, 0);
                tv_days.setText("已连续签到" + (days + 1) + "天");
                break;

            //查看明细
            case R.id.rl_detail:
                intent = new Intent(SignInActivity.this, LookDetailActivity.class);
                startActivity(intent);
                break;

            //积分商城
            case R.id.rl_shopping:
                intent = new Intent(SignInActivity.this, IntegralShoppingActivity.class);
                startActivity(intent);
                break;

            default:
                break;
        }
    }
}
